//
//  UIImage+other.m
//  UnionDrugHealthy
//
//  Created by duanan on 2020/3/5.
//  Copyright © 2020 duanan. All rights reserved.
//

#import "UIImage+other.h"
#define UIColorFromRGBAUIImage(rgbValue,alphaValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]

 
@implementation UIImage (other)

+ (UIImage *)makePlaceholderWithSize:(CGSize)size{
    
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width+2, size.height+2)];
    UIImageView* cententImage =[UIImageView new];
    view.backgroundColor = UIColorFromRGBAUIImage(0xf6f6f6, 1);
    cententImage.contentMode = UIViewContentModeScaleAspectFit ;
    cententImage.image = [UIImage imageNamed:@"udplaceholder"];
    [view addSubview:cententImage];
    
    int w = size.width > size.height ?  size.height : size.width ;
    cententImage.frame = CGRectMake(0, 0, w*0.6, w*0.6) ;
    cententImage.center = view.center ;
    
    CGSize s = size;
    
    UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end
